#ifndef MAIN_HAL_UTILS_TRACE_H_
#define MAIN_HAL_UTILS_TRACE_H_

#include <stdio.h>

#include <iostream>
#include <stdio.h>
#include <stdarg.h>

#include "c3log.h"

#define TRACE_B(...) \
    Trace trace; \
    trace.begin(LOG_TAG, __func__, ##__VA_ARGS__);

class Trace{
 public:
    bool mLogOn = true;
    char mTag[48]={0};
    Trace() {
    }

    ~Trace() {
        if (mLogOn) {
            log_tag("\033[0;32m", "I", "", "[T_END] %s X", mTag);
        }
    }

    bool begin(const char *logtagstr, const char *func_name) {
        return begin(logtagstr, func_name, "");
    }

    bool begin(const char *logtagstr, const char *func_name, const char *format, ...){
        if (mLogOn) {
            va_list args;
            va_start(args, format);
            int len = snprintf(mTag, sizeof(mTag), "%s %s() ", logtagstr, func_name);
            vsnprintf(mTag + len, sizeof(mTag) - len, format, args);
            va_end(args);
            log_tag("\033[0;32m", "I", "", "[T_BEG] %s E", mTag);
        } else {
            return false;
        }

        return true;
    }
};

#endif /* MAIN_HAL_UTILS_TRACE_H_ */
